package com.baofu.paycore.service.converter;

import com.baofu.paycore.common.enums.FundBelongTypeEnum;
import com.baofu.paycore.common.enums.FundTypeEnum;
import com.baofu.paycore.manager.model.*;
import com.baofu.paycore.service.facade.enums.PayStatusEnums;
import com.baofu.paycore.service.facade.enums.PayToolSubTypeEnum;
import com.baofu.paycore.service.facade.enums.PayToolTypeEnum;
import com.baofu.paycore.service.facade.enums.RequestSystemEnum;

/**
 * 对象转换器
 * <p>
 * </p>
 * User: kwl Date: 2016/6/7 ProjectName: paycore Version: 5.0.0
 */
public class BO2BOConverter {

    /**
     * 构建退款资金明细单
     *
     * @param subPayBO       原支付资金明细单
     * @param refundBO       退款主单信息
     * @param subRefundBO    退款资金明细单
     * @return               退款资金明细单
     */
    public static SubRefundBO getSubRefundBOBySubPayBO(SubPayBO subPayBO, RefundBO refundBO,
                                                       SubRefundBO subRefundBO){

        subRefundBO.setPayNo(refundBO.getPayNo());
        //subRefundBO.setRelateFundDetailNo(subPayBO.getFundDetailNo());

        //退款原单相关参数设置
        subRefundBO.setOrigTransReceiptNo(subPayBO.getTransReceiptNo());
        subRefundBO.setOrigTransDate(subPayBO.getTransDate());
        subRefundBO.setOrigRequestBizNo(subPayBO.getFundDetailNo());
        subRefundBO.setOrigRequestSystem(RequestSystemEnum.PAYCORE.getCode());
        subRefundBO.setOrigRequestDate(refundBO.getOrigRequestDate());

        subRefundBO.setFundType(FundTypeEnum.TRANSFER_REFUND.getCode());
        subRefundBO.setClassType(subPayBO.getClassType());

        subRefundBO.setPayerAccNo(subPayBO.getPayeeAccNo());
        subRefundBO.setPayeeAccNo(subPayBO.getPayerAccNo());

        subRefundBO.setPayToolType(subRefundBO.getPayToolType());
        subRefundBO.setPayToolSubType(subPayBO.getPayToolSubType());
        subRefundBO.setBizType(refundBO.getBizType());
        subRefundBO.setSubBizType(refundBO.getSubBizType());
        subRefundBO.setFundingChannel(subPayBO.getFundingChannel());
        subRefundBO.setSubFundingChannel(subPayBO.getSubFundingChannel());

        subRefundBO.setFundBelong(FundBelongTypeEnum.PAYEE.getCode());
        subRefundBO.setCcy(subPayBO.getCcy());
        subRefundBO.setAmt(subRefundBO.getAmt());

        subRefundBO.setAgreementNo(subRefundBO.getAgreementNo());
        subRefundBO.setAgreeRelId(subRefundBO.getAgreeRelId());
        subRefundBO.setBankCode(subRefundBO.getBankCode());
        subRefundBO.setCardType(subRefundBO.getCardType());

        subRefundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundBO.setDescription(refundBO.getDescription());
        subRefundBO.setOperator(refundBO.getOperator());
        return subRefundBO;
    }

    /**
     * 构建原充值银行卡单退款资金明细
     *
     * @param subPayBO           原支付资金明细单
     * @param refundBO           退款主单信息
     * @param subRefundFundBO    退款资金明细单
     * @param rechargeBankBO     清分银行卡支付资金单
     * @return                   退款资金明细单
     */
    public static SubRefundBO getSubRefundBOByRechargeBankBO(SubPayBO subPayBO, RefundBO refundBO,
                                                             SubRefundBO subRefundFundBO,
                                                             RechargeBankBO rechargeBankBO){

        subRefundFundBO.setPayNo(refundBO.getPayNo());
        //subRefundFundBO.setRelateFundDetailNo(subPayBO.getFundDetailNo());
        subRefundFundBO.setFundType(FundTypeEnum.PAY_BANK_REFUND.getCode());
        subRefundFundBO.setClassType(subPayBO.getClassType());

        subRefundFundBO.setOrigTransReceiptNo(rechargeBankBO.getTransReceiptNo());
        subRefundFundBO.setOrigTransDate(rechargeBankBO.getTransDate());
        subRefundFundBO.setOrigRequestOrderNo(rechargeBankBO.getPayNo());
        subRefundFundBO.setOrigRequestBizNo(rechargeBankBO.getFundDetailNo());
        subRefundFundBO.setOrigRequestSystem(RequestSystemEnum.PAYCORE.getCode());
        subRefundFundBO.setOrigRequestDate(refundBO.getOrigRequestDate());


        //退款的收款资金账户为原支付交易的付款账户，同时退款的付款账户为原支付单的收款账户
        subRefundFundBO.setPayerAccNo(subPayBO.getPayeeAccNo());
        subRefundFundBO.setPayeeAccNo(subPayBO.getPayerAccNo());

        subRefundFundBO.setPayToolType(subRefundFundBO.getPayToolType());
        subRefundFundBO.setPayToolSubType(rechargeBankBO.getPayToolSubType());
        subRefundFundBO.setBizType(refundBO.getBizType());
        subRefundFundBO.setSubBizType(refundBO.getSubBizType());
        subRefundFundBO.setFundingChannel(rechargeBankBO.getFundChannel());
        subRefundFundBO.setSubFundingChannel(rechargeBankBO.getSubFundChannel());

        subRefundFundBO.setFundBelong(FundBelongTypeEnum.PAYEE.getCode());
        subRefundFundBO.setCcy(subPayBO.getCcy());

        subRefundFundBO.setAgreementNo(rechargeBankBO.getAgreementNo());
        subRefundFundBO.setAgreeRelId(rechargeBankBO.getAgreeRelId());
        subRefundFundBO.setBankCode(rechargeBankBO.getBankCode());
        subRefundFundBO.setCardType(rechargeBankBO.getCardType());

        subRefundFundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundFundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundFundBO.setDescription(refundBO.getDescription());
        subRefundFundBO.setOperator(refundBO.getOperator());

        return subRefundFundBO;
    }

    /**
     * 构建原充值账务充值单退款资金明细
     *
     * @param subPayBO           原支付资金明细单
     * @param refundBO           退款主单信息
     * @param subRefundFundBO    退款资金明细单
     * @param rechargeFundBO     充值资金明细单
     * @return                   退款资金明细单
     */
    public static SubRefundBO getSubRefundBOByRechargeFundBO(SubPayBO subPayBO,RefundBO refundBO,
                                                             SubRefundBO subRefundFundBO,
                                                             RechargeFundBO rechargeFundBO){

        subRefundFundBO.setPayNo(refundBO.getPayNo());
        //subRefundFundBO.setRelateFundDetailNo(subPayBO.getFundDetailNo());
        subRefundFundBO.setFundType(FundTypeEnum.PAY_RECHARGE_REFUND.getCode());
        subRefundFundBO.setClassType(subPayBO.getClassType());

        subRefundFundBO.setOrigTransReceiptNo(rechargeFundBO.getTransReceiptNo());
        subRefundFundBO.setOrigTransDate(rechargeFundBO.getTransDate());
        subRefundFundBO.setOrigRequestOrderNo(rechargeFundBO.getPayNo());
        subRefundFundBO.setOrigRequestBizNo(rechargeFundBO.getFundDetailNo());
        subRefundFundBO.setOrigRequestSystem(RequestSystemEnum.PAYCORE.getCode());
        subRefundFundBO.setOrigRequestDate(refundBO.getOrigRequestDate());

        //退款的收款资金账户为原支付交易的付款账户，同时退款的付款账户为原支付单的收款账户
        subRefundFundBO.setPayerAccNo(rechargeFundBO.getAccountNo());

        subRefundFundBO.setPayToolSubType(rechargeFundBO.getPayToolSubType());
        subRefundFundBO.setFundingChannel(rechargeFundBO.getFundChannel());
        subRefundFundBO.setSubFundingChannel(rechargeFundBO.getFundSubChannel());

        subRefundFundBO.setFundBelong(FundBelongTypeEnum.PAYEE.getCode());
        subRefundFundBO.setCcy(subPayBO.getCcy());

        subRefundFundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundFundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundFundBO.setDescription(refundBO.getDescription());
        subRefundFundBO.setOperator(refundBO.getOperator());

        return subRefundFundBO;
    }

    /**
     * 构建退款收手续费资金明细单
     *
     * @param refundBO       退款主单信息
     * @param subRefundBO    退款资金明细单
     * @return               退款资金明细单
     */
    public static SubRefundBO getSubRefundBOByFeeAmt(RefundBO refundBO,SubRefundBO subRefundBO){

        subRefundBO.setPayNo(refundBO.getPayNo());
        subRefundBO.setFundType(FundTypeEnum.FEE.getCode());
        subRefundBO.setClassType(PayToolTypeEnum.ACCOUNT.getCode());

        subRefundBO.setPayToolType(subRefundBO.getPayToolType());
        subRefundBO.setPayToolSubType(PayToolSubTypeEnum.ACCOUNT.getSubPayToolCode());
        subRefundBO.setBizType(refundBO.getBizType());
        subRefundBO.setSubBizType(refundBO.getSubBizType());

        subRefundBO.setFundBelong(FundBelongTypeEnum.PAYER.getCode());
        subRefundBO.setCcy(refundBO.getCcy());
        subRefundBO.setAmt(refundBO.getFeeAmt());

        subRefundBO.setAgreementNo(subRefundBO.getAgreementNo());
        subRefundBO.setAgreeRelId(subRefundBO.getAgreeRelId());
        subRefundBO.setBankCode(subRefundBO.getBankCode());
        subRefundBO.setCardType(subRefundBO.getCardType());

        subRefundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundBO.setDescription(refundBO.getDescription());
        subRefundBO.setOperator(refundBO.getOperator());
        return subRefundBO;
    }
    /**
     * 构建退款收手续费资金明细单
     *
     * @param subPayBO       原资金单信息
     * @param refundBO       退款主单信息
     * @param subRefundBO    退款资金明细单
     * @return               退款资金明细单
     */
    public static SubRefundBO getRefundFreezeBO(SubPayBO subPayBO, RefundBO refundBO,SubRefundBO subRefundBO){

        subRefundBO.setPayNo(refundBO.getPayNo());
        subRefundBO.setFundType(FundTypeEnum.REFUND_FREEZE.getCode());
        subRefundBO.setClassType(PayToolTypeEnum.ACCOUNT.getCode());

        subRefundBO.setPayToolType(subRefundBO.getPayToolType());
        subRefundBO.setPayToolSubType(PayToolSubTypeEnum.ACCOUNT.getSubPayToolCode());
        subRefundBO.setBizType(refundBO.getBizType());
        subRefundBO.setSubBizType(refundBO.getSubBizType());

        //退款的冻结资金账户为原支付交易的付款账户，且冻结只有出账账户
        subRefundBO.setPayerAccNo(subPayBO.getPayeeAccNo());

        subRefundBO.setFundBelong(FundBelongTypeEnum.PAYER.getCode());
        subRefundBO.setCcy(refundBO.getCcy());
        subRefundBO.setAmt(refundBO.getFeeAmt());

        subRefundBO.setAgreementNo(subRefundBO.getAgreementNo());
        subRefundBO.setAgreeRelId(subRefundBO.getAgreeRelId());
        subRefundBO.setBankCode(subRefundBO.getBankCode());
        subRefundBO.setCardType(subRefundBO.getCardType());

        subRefundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundBO.setDescription(refundBO.getDescription());
        subRefundBO.setOperator(refundBO.getOperator());
        return subRefundBO;
    }

    /**
     * 构建退款资金明细单
     *
     * @param subPayBO       原支付资金明细单
     * @param refundBO       退款主单信息
     * @param subRefundBO    退款资金明细单
     * @return               退款资金明细单
     */
    public static SubRefundBO getRefundUnFreezeTransferBO(SubPayBO subPayBO, RefundBO refundBO,
                                                          SubRefundBO subRefundBO){

        subRefundBO.setPayNo(refundBO.getPayNo());
        subRefundBO.setFundType(FundTypeEnum.UNFREEZE_TRANSFER.getCode());
        subRefundBO.setClassType(PayToolTypeEnum.ACCOUNT.getCode());

        //退款原单相关参数设置
        subRefundBO.setOrigTransReceiptNo(subPayBO.getTransReceiptNo());
        subRefundBO.setOrigTransDate(subPayBO.getTransDate());
        subRefundBO.setOrigRequestBizNo(subPayBO.getFundDetailNo());
        subRefundBO.setOrigRequestSystem(RequestSystemEnum.PAYCORE.getCode());
        subRefundBO.setOrigRequestDate(refundBO.getOrigRequestDate());

        subRefundBO.setPayerAccNo(subPayBO.getPayeeAccNo());
        subRefundBO.setPayeeAccNo(subPayBO.getPayerAccNo());

        subRefundBO.setPayToolType(subRefundBO.getPayToolType());
        subRefundBO.setPayToolSubType(subPayBO.getPayToolSubType());
        subRefundBO.setBizType(refundBO.getBizType());
        subRefundBO.setSubBizType(refundBO.getSubBizType());
        subRefundBO.setFundingChannel(subPayBO.getFundingChannel());
        subRefundBO.setSubFundingChannel(subPayBO.getSubFundingChannel());

        subRefundBO.setFundBelong(FundBelongTypeEnum.PAYEE.getCode());
        subRefundBO.setCcy(subPayBO.getCcy());
        subRefundBO.setAmt(subRefundBO.getAmt());

        subRefundBO.setAgreementNo(subRefundBO.getAgreementNo());
        subRefundBO.setAgreeRelId(subRefundBO.getAgreeRelId());
        subRefundBO.setBankCode(subRefundBO.getBankCode());
        subRefundBO.setCardType(subRefundBO.getCardType());

        subRefundBO.setStatus(PayStatusEnums.INIT.getCode());

        subRefundBO.setFdDtlExtra(refundBO.getRefundExtra());
        subRefundBO.setDescription(refundBO.getDescription());
        subRefundBO.setOperator(refundBO.getOperator());
        return subRefundBO;
    }

}
